<template>
  <div class="container">
    <el-form :model="loginForm" class="login-form" status-icon @submit.prevent>
      <h2 class="title">欢迎使用 sc-admin</h2>
      <el-form-item prop="username">
        <el-input
          v-model="loginForm.username"
          placeholder="请输入用户名(admin)"
          size="large"
        />
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          v-model="loginForm.password"
          placeholder="请输入密码(admin)"
          show-password
          size="large"
        />
      </el-form-item>
      <el-form-item class="login-btn-container">
        <el-button class="login-btn" type="primary" native-type="submit" @click="onSubmit">
          登录
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script lang="ts" setup>
import useUserStore from "@/store/modules/useUserStore";
const loginForm = reactive({
  username: "",
  password: "",
});

const userStore = useUserStore();
const router = useRouter();
async function onSubmit() {
  const userInfo = await userStore.loginAction(loginForm);
  if (userInfo) {
    router.push({ name: "home" });
  }
}
</script>

<style scoped>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(145deg, white 20%, lightblue, white);
}

.login-form {
  padding: 25px 50px;
  width: 600px;
  height: 400px;
  background-color: #fff;
  border-radius: 30px;
  box-shadow: 0 0 10px 2px lightslategray;
  transform: translateY(-50px);
}

.title {
  margin: 20px 0;
  font-size: 40px;
  text-align: center;
}

.login-btn-container {
  margin-top: 30px;
}

.login-btn {
  width: 100%;
  height: 40px;
}
</style>
